package me.lxw.blogsystem.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import me.lxw.blogsystem.dao.ArticleDAO;
import me.lxw.blogsystem.domain.Article;

@WebServlet("/article.do")
public class ArticleServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 获取参数
		String id = request.getParameter("id");

		// 1.获取数据

		ArticleDAO articleDAO = new ArticleDAO();
		try {

			Article article = articleDAO.findById(Integer.valueOf(id));
			articleDAO.modifyView(Integer.valueOf(id));

			// 2.将站点信息保存到请求域，

			request.setAttribute("article", article);

			// 3.请求转发到index.jsp
			request.getRequestDispatcher("/front/article.jsp").forward(request, response);
		} catch (SQLException e) {

			e.printStackTrace();
		}
	}

}
